from django.dispatch import Signal
from django.db.models.signals import post_save

from accounts.models import *

account_created = Signal() # Sent when an account is finished creating (all steps, Site, Users, etc).
rate_plan_changed = Signal(providing_args=["old_plan", "new_plan"]) # Signal that gets sent when an Account changes rate plans. 

def attach_account_profile(sender, **kwargs):
	"Ensures an Account has an associated profile, if one is specified in settings."
	model = get_account_profile_model()
	if model:
		model._default_manager.get_or_create(account=kwargs['instance'])


def attach_account_user_profile(sender, **kwargs):
	"Ensures an AccountUser has the associated user profile, if one is specified in settings."
	model = get_account_user_profile_model()
	if model:
		model._default_manager.get_or_create(account_user=kwargs['instance'])


post_save.connect(attach_account_profile, sender=Account)
post_save.connect(attach_account_user_profile, sender=AccountUser)
